<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <svg width="100%" height="200">
        <rect x="20" y="20" width="100" height="100"> </rect>
    </svg>
    <button>点击</button>
</body>
<script>
    function throttle(fun, wait) {
        let timer;
        return (...args) => {
            console.log(123);
            if (timer) {
                return
            } else {
                timer = setTimeout(() => {
                    timer = null
                    fun(...args)
                }, wait)
            }
        }
    }
    const btn = document.querySelector('button')
    const svgRect = document.querySelector('rect')

    btn.addEventListener('click', throttle(() => {
        const svgRect = document.querySelector('rect')
        let wizhi = 20
        time = setInterval(() => {
            wizhi += 2
            svgRect.setAttribute('width', wizhi)
            if (wizhi == 200) {
                clearInterval(time)
                time = null;
            }
        }, 10)
    }, 2000))
</script>

</html>